home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / projectSetup.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  23.4 KB  |  955 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  Feb. 6, 1997
  22. //    Author:            DSW
  23. //
  24. //  Description:
  25. //      Project Create/Setup window.
  26. //
  27. //  Input Arguments:
  28. //        None
  29. // 
  30. //  Return Value:
  31. //        None
  32. //
  33.  
  34. proc string[] np_getObjectWidgets(string $wsName)
  35. {
  36.     string $defaults[] =
  37.     {
  38. //        Label            Widget            Default            Current
  39.         "Scenes",        "scene",        "scenes",        ""
  40.     };
  41.  
  42.     if ($wsName != "")
  43.     {
  44.         string $ot[] = `workspace -q -ot $wsName`;
  45.  
  46.         int $i, $j;
  47.         int $found;
  48.  
  49.         for ($i = 0; $i < size($ot); $i += 2)
  50.         {
  51.             $found = 0;
  52.  
  53.             for ($j = 0; $j < size($defaults); $j += 4)
  54.             {
  55.                 if ($ot[$i] == $defaults[$j + 1])
  56.                 {
  57.                     $defaults[$j + 3] = $ot[$i + 1];
  58.                     $found = 1;
  59.                     break;
  60.                 }
  61.             }
  62.  
  63.             if (!$found)
  64.             {
  65.                 // No, this is not a cut and paste error.  This line
  66.                 // should b repeated 4 times.
  67.                 //
  68.                 $defaults[size($defaults)] = $ot[$i];
  69.                 $defaults[size($defaults)] = $ot[$i];
  70.                 $defaults[size($defaults)] = $ot[$i];
  71.                 $defaults[size($defaults)] = `workspace -ote $ot[$i] $wsName`;
  72.             }
  73.         }
  74.     }
  75.  
  76.     return $defaults;
  77. }
  78.  
  79. proc string[] np_getRenderWidgets(string $wsName)
  80. {
  81.     string $defaults[] =
  82.     {
  83. //        Label            Widget               Default                    Current
  84.         "Images",        "images",        "images",                "",
  85.         "Source Images","sourceImages",    "sourceimages",            "",
  86.         "Clips",        "clips",        "clips",                "",
  87.         "Sound",        "audio",        "sound",                "",
  88.         "Particles",    "particles",    "particles",            "",
  89.         "Render Scenes","renderScenes",    "renderScenes",            "",
  90.         "Depth",        "depth",        "renderData/depth",        "",
  91.         "IPR Images",    "iprImages",    "renderData/iprImages",    "",
  92.         // This naming admittedly doesn't make much sense - textures should be
  93.         // shaders, lights should be lights. Since 3dPaint is now using 
  94.         // textures we're going to point both lights and (hypershade-
  95.         // exported) shaders into the 'lights' location (and add a separate
  96.         // 'shaders' location later...)
  97.         "Shaders",        "lights",        "renderData/shaders",    "",
  98.         "Textures",        "textures",        "textures",                "",
  99.         "Mel",            "mel",            "",                    "",
  100.         "3dPaintTextures",    "3dPaintTextures",    "3dPaintTextures",            ""
  101.     };
  102.  
  103.     if ($wsName != "")
  104.     {
  105.         string $rt[] = `workspace -q -rt $wsName`;
  106.  
  107.         int $i, $j;
  108.         int $found;
  109.  
  110.         for ($i = 0; $i < size($rt); $i += 2)
  111.         {
  112.             $found = 0;
  113.  
  114.             for ($j = 0; $j < size($defaults); $j += 4)
  115.             {
  116.                 if ($rt[$i] == $defaults[$j + 1])
  117.                 {
  118.                     $defaults[$j + 3] = $rt[$i + 1];
  119.                     $found = 1;
  120.                     break;
  121.                 }
  122.             }
  123.  
  124.             if (!$found)
  125.             {
  126.                 // No, this is not a cut and paste error.  This line
  127.                 // should be repeated 3 times.
  128.                 //
  129.                 $defaults[size($defaults)] = $rt[$i];
  130.                 $defaults[size($defaults)] = $rt[$i];
  131.                 $defaults[size($defaults)] = $rt[$i];
  132.                 $defaults[size($defaults)] = `workspace -rte $rt[$i] $wsName`;
  133.             }
  134.         }
  135.     }
  136.  
  137.     return $defaults;
  138. }
  139.  
  140. proc string[] np_getTranslatorWidgetMap()
  141. {
  142.     string $map[] =
  143.     {
  144. //        Translator        Widget
  145.         "DXF",            "dxf",
  146.         "DXFexport",    "dxf",
  147.         "IGES",            "iges",
  148.         "IGESexport",    "iges",
  149.         "OBJ",            "obj",
  150.         "OBJexport",    "obj",
  151.         "RIB",            "rib",
  152.         "RIBexport",    "rib",
  153.         "aliasWire",    "wire",
  154.         "animImport",    "anim",
  155.         "animExport",    "anim",
  156.         "EPS",            "eps",
  157.         "Illustrator",    "illustrator",
  158.         "diskCache",    "diskCache"
  159.     };
  160.  
  161.     return $map;
  162. }
  163.  
  164. proc string[] np_getFileRuleWidgets(string $wsName)
  165. {
  166.     // These lines should be visible always
  167.     //
  168.     string $defaults[] =
  169.     {
  170. //        Label                Widget                Default                Current
  171.         "Image",            "image",            "images",            "",
  172.         "DXF",                "dxf",                "data",                "",
  173.         "IGES",                "iges",                "data",                "",
  174.         "OBJ",                "obj",                "data",                "",
  175.         "RIB",                "rib",                "data",                "",
  176.         "Wire",                "wire",                "data",                "",
  177.         "Move",                "move",                "data",                "",
  178.         "Anim",                "anim",                "data",                "",
  179.         "EPS",                "eps",                "data",                "",
  180.         "Illustrator",        "illustrator",        "data",                "",
  181.         "Disk Cache",        "diskCache",        "data",                ""
  182.     };
  183.  
  184.     // This is a list of translators to completely ignore
  185.     //
  186.     string $ignore[] =
  187.     {
  188.         "mayaAscii",
  189.         "mayaBinary",
  190.         "mayaPLE",
  191.         "directory",
  192.         "plug-in",
  193.         // The following are either old translator names or
  194.         // were introduced in error during development.  They
  195.         // should be cleaned up.
  196.         //
  197.         "dxf",            // should be DXF
  198.         "iges",            // should be IGES
  199.         "aiff",            // should be audio
  200.         "images",        // should be image
  201.         "audio"            // It's handled in Project data
  202.     };
  203.  
  204.     int $i, $j;
  205.     int $found, $skip;
  206.     string $map[] = np_getTranslatorWidgetMap();
  207.     string $widget;
  208.  
  209.     string $trans[] = `translator -q -l`;
  210.  
  211.     // If we have a workspace, add the current file rules
  212.     //
  213.     if ($wsName != "")
  214.     {
  215.         string $rules[] = `workspace -q -frl`;
  216.  
  217.         for ($i = 0; $i < size($rules); ++$i)
  218.         {
  219.             $trans[size($trans)] = $rules[$i];
  220.         }
  221.     }
  222.  
  223.     for ($i = 0; $i < size($trans); ++$i)
  224.     {
  225.         $widget = $trans[$i];
  226.  
  227.         $skip = 0;
  228.         // See if this translator should be ignored
  229.         for ($j = 0; $j < size($ignore); ++$j)
  230.         {
  231.             if ($widget == $ignore[$j])
  232.             {
  233.                 $skip = 1;
  234.                 break;
  235.             }
  236.         }
  237.  
  238.         if ($skip)
  239.         {
  240.             continue;
  241.         }
  242.  
  243.         // Map the translator name to a widget
  244.         //
  245.         for ($j = 0; $j < size($map); $j += 2)
  246.         {
  247.             if ($widget == $map[$j])
  248.             {
  249.                 $widget = $map[$j + 1];
  250.                 break;
  251.             }
  252.         }
  253.  
  254.         // See if the translator is already in the list so we
  255.         // don't add it twice.
  256.         //
  257.         for ($j = 0; $j < size($defaults); $j += 4)
  258.         {
  259.             if ($widget == $defaults[$j + 1])
  260.             {
  261.                 // Yep, we've seen this one already
  262.                 if ($wsName != "")
  263.                 {
  264.                     $defaults[$j + 3] = `workspace -q -fre $trans[$i]`;
  265.                 }
  266.                 $skip = 1;
  267.                 break;
  268.             }
  269.         }
  270.  
  271.         if ($skip)
  272.         {
  273.             continue;
  274.         }
  275.  
  276.         string $defaultLocation = $widget;
  277.         if ( gmatch( $trans[$i], "fur*" ) )
  278.         {
  279.             $defaultLocation = "fur/" + $widget;
  280.         }
  281.  
  282.         // Having made it this far, add it to the list of widgets
  283.         //
  284.         $defaults[size($defaults)] = $trans[$i];
  285.         $defaults[size($defaults)] = $widget;
  286.         $defaults[size($defaults)] = $defaultLocation;
  287.         if ($wsName == "")
  288.         {
  289.             $defaults[size($defaults)] = "";
  290.         }
  291.         else
  292.         {
  293.             $defaults[size($defaults)] = `workspace -q -fre $trans[$i]`;
  294.         }
  295.     }
  296.  
  297.     return $defaults;
  298. }
  299.  
  300. global proc np_resetDefaults ( )
  301. //
  302. //    Description:
  303. //        Fill in the project defaults.
  304. //
  305. {
  306.     string    $objectWidgets[]   = np_getObjectWidgets("");
  307.     string    $renderWidgets[]   = np_getRenderWidgets("");
  308.     string    $fileRuleWidgets[] = np_getFileRuleWidgets("");
  309.  
  310.     int        $listSize;
  311.     int        $index;
  312.  
  313.     $listSize = size($objectWidgets);
  314.  
  315.     for ($index = 0; $index < $listSize; $index += 4)
  316.     {
  317.         string $name = "np_ObjectLocation" + $objectWidgets[$index + 1];
  318.         string $value = $objectWidgets[$index + 2];
  319.  
  320.         textFieldGrp -e -fileName $value $name;
  321.     }
  322.  
  323.     $listSize = size($renderWidgets);
  324.  
  325.     for ($index = 0; $index < $listSize; $index += 4)
  326.     {
  327.         string $name = "np_RenderLocation" + $renderWidgets[$index + 1];
  328.         string $value = $renderWidgets[$index + 2];
  329.  
  330.         textFieldGrp -e -fileName $value $name;
  331.     }
  332.  
  333.     $listSize = size($fileRuleWidgets);
  334.  
  335.     for ($index = 0; $index < $listSize; $index += 4)
  336.     {
  337.         string $name = "np_FileLocation" + $fileRuleWidgets[$index + 1];
  338.         string $value = $fileRuleWidgets[$index + 2];
  339.  
  340.         textFieldGrp -e -fileName $value $name;
  341.     }
  342. }
  343.  
  344.  
  345. global proc int np_createNewProjectCallback ( )
  346. //
  347. //    Description:
  348. //        Create a new workspace and generate all of the
  349. //        sub directories under it using the user defined defaults.
  350. //
  351. //    Returns true if the project was created OK.
  352. //            false otherwise.
  353. //
  354. //    Notes:
  355. //        This has the side effect of setting the workspace to the
  356. //        newly created workspace.
  357. //
  358. {
  359.     string $pathSep = ":";
  360.     if (`about -nt`) {
  361.         $pathSep = ";";
  362.     }
  363.  
  364.     string $shortWSName; 
  365.     string $wsLocation;
  366.     string $wsRootDir;
  367.     string $project;
  368.  
  369.     $shortWSName = `textFieldGrp -q -text ("np_wsName0")`;
  370.     $wsLocation = `textFieldGrp -q -fileName ("wsLocation0")`;
  371. //    $wsRootDir = `textFieldGrp -q -fileName ("wsRootDir0")`;
  372.  
  373.     int $locationSize = size($wsLocation);
  374.     if ($shortWSName == "") {
  375.         confirmDialog -m ("No Project Name Given") 
  376.             -b "OK" -db "OK" -parent newProjectWindow;
  377.         return false;
  378.     }    
  379.     if ($locationSize <= 0) {
  380.         confirmDialog -m ("No Project Location Given") 
  381.             -b "OK" -db "OK" -parent newProjectWindow;
  382.         return false;
  383.     }    
  384.  
  385.     if (match("/$", $wsLocation) != "/") {
  386.         $project = $wsLocation + "/" + $shortWSName;
  387.     } else {
  388.         $project = $wsLocation + $shortWSName;
  389.     }
  390.  
  391.     // Verify that it doesn't exist.
  392.     if (`file -q -ex ($project + "/workspace.mel")`) {
  393.         // Then the project exists.
  394.         confirmDialog -m ($project+" Exists") 
  395.             -b "OK" -db "OK" -parent newProjectWindow;
  396.         return false;
  397.     }
  398.  
  399.     workspace -cr $project;
  400.  
  401.     if (!(`file -q -ex $project`)) {
  402.         confirmDialog -m ("Failed to Create "+$project) 
  403.             -b "OK" -db "OK" -parent newProjectWindow;
  404.         return false;
  405.     }    
  406.  
  407.     // Open the project
  408.     //
  409.     workspace -o $project;
  410.  
  411.     // Call the edit callback to set all the values and create
  412.     // necessary directories
  413.     //
  414.     np_editProjectCallback();
  415.  
  416.     // Reset the prefs for the browser with project specific stuff.
  417.     //
  418.     np_resetBrowserPrefs;
  419.  
  420.     addRecentProject( $project );
  421.  
  422.     return true;
  423. }
  424.  
  425. global proc int np_editProjectCallback ( )
  426. //
  427. //  Description:
  428. //      Update the project setup using the user supplied information.
  429. //
  430. //  Note:
  431. //      Old directories won't be removed because of the update however
  432. //      they may become unused.
  433. //
  434. {
  435. global string $gProjectSetupWorkspace;
  436.  
  437.     string $pathSep = ":";
  438.     if (`about -nt`) {
  439.         $pathSep = ";";
  440.     }
  441.  
  442.     // Make sure we go to the project root directory before
  443.     // creating any new directories.
  444.     //
  445.     string    $origDir = `workspace -q -dir`;
  446.     workspace -dir `workspace -q -rd`;
  447.  
  448.     string    $objectWidgets[];
  449.     string    $renderWidgets[];
  450.     string    $fileRuleWidgets[];
  451.  
  452.     string    $fileRuleMap[];
  453.  
  454.     $objectWidgets   = np_getObjectWidgets($gProjectSetupWorkspace);
  455.     $renderWidgets   = np_getRenderWidgets($gProjectSetupWorkspace);
  456.     $fileRuleWidgets = np_getFileRuleWidgets($gProjectSetupWorkspace);
  457.  
  458.     $fileRuleMap     = np_getTranslatorWidgetMap();
  459.  
  460.     int     $index;
  461.     int     $listSize;
  462.     string    $locations[];
  463.  
  464.     $listSize = size($objectWidgets);
  465.  
  466.     for ($index = 0; $index < $listSize; $index += 4)
  467.     {
  468.         string $objtype = $objectWidgets[$index + 1];
  469.         string $name  = "np_ObjectLocation" + $objtype;
  470.         string $value;
  471.  
  472.         $value = `textFieldGrp -q -fileName $name`;
  473.         workspace -ot $objtype $value;
  474.  
  475.         if ($value != "")
  476.         {
  477.             if (tokenize($value, $pathSep, $locations) > 0)
  478.             {
  479.                 workspace -cr $locations[0];
  480.             }
  481.         }
  482.     }
  483.  
  484.     $listSize = size($renderWidgets);
  485.  
  486.     for ($index = 0; $index < $listSize; $index += 4)
  487.     {
  488.         string $rentype = $renderWidgets[$index + 1];
  489.         string $name  = "np_RenderLocation" + $rentype;
  490.         string $value;
  491.  
  492.         $value = `textFieldGrp -q -fileName $name`;
  493.         workspace -rt $rentype $value;
  494.  
  495.         if ($value != "")
  496.         {
  497.             if (tokenize($value, $pathSep, $locations) > 0)
  498.             {
  499.                 workspace -cr $locations[0];
  500.             }
  501.         }
  502.     }
  503.  
  504.     $listSize = size($fileRuleWidgets);
  505.  
  506.     for ($index = 0; $index < $listSize; $index += 4)
  507.     {
  508.         string $frtype = $fileRuleWidgets[$index + 1];
  509.         string $name  = "np_FileLocation" + $frtype;
  510.         string $value;
  511.         int $j, $found;
  512.  
  513.         $value = `textFieldGrp -q -fileName $name`;
  514.  
  515.         $found = 0;
  516.         for ($j = 0; $j < size($fileRuleMap); $j += 2)
  517.         {
  518.             if ($frtype == $fileRuleMap[$j + 1])
  519.             {
  520.                 $found = 1;
  521.                 workspace -fr $fileRuleMap[$j] $value;
  522.             }
  523.         }
  524.  
  525.         if (!$found)
  526.         {
  527.             workspace -fr $frtype $value;
  528.         }
  529.  
  530.         if ($value != "")
  531.         {
  532.             if (tokenize($value, $pathSep, $locations) > 0)
  533.             {
  534.                 workspace -cr $locations[0];
  535.             }
  536.         }
  537.     }
  538.  
  539.     workspace -u;
  540.     workspace -s;
  541.  
  542.     // Restore the original directory
  543.     //
  544.     workspace -dir $origDir;
  545.  
  546.     // If the browser is up then we must reset it.
  547.     //
  548.  
  549.     if (`window -ex projectViewerWindow`) {
  550.         pv_resetWorkspace;    // Force the layout to be redone.
  551.     }
  552.  
  553.     return true;
  554. }
  555.  
  556. proc np_showSetup ( string $wsFullName, string $parent, int $bUseDefaults, int $bEditable ) 
  557. //
  558. //    Description:
  559. //        Display the setup information for either the specified workspace
  560. //         or the preference defaults.
  561. //
  562. //    Parameters:
  563. //        $wsFullName        - the full name of the workspace.
  564. //        $parent            - the parent controlLayout.
  565. //        $bUseDefaults    - Fill with defaults.
  566. //        $bEditable        - if true then make the fields editable.
  567. //
  568. {
  569.     string $np_wsRuleList = ("np_wsRuleList");
  570.     string $itemList[];
  571.     int $listSize;
  572.     int $listSize2;
  573.     int $index;
  574.     int $index2;
  575.     string $curTypeRules[];
  576.     string $curObjectRules[];
  577.     string $curRenderRules[];
  578.     string $tmpString;            // Multi use string.
  579.     int $bFound;
  580.     string $curLocation;
  581.     int $justFill;
  582.     string $tfgName;
  583.     int    $useWorkspace = $wsFullName != "";
  584.  
  585.     string $objectWidgets[]   = np_getObjectWidgets($wsFullName);
  586.     string $renderWidgets[]   = np_getRenderWidgets($wsFullName);
  587.     string $fileRuleWidgets[] = np_getFileRuleWidgets($wsFullName);
  588.  
  589.     if (`columnLayout -ex $np_wsRuleList`) {
  590.         // The window is already filled in so just replace contents.
  591.         $justFill = 1;
  592.     } else {
  593.         $justFill = 0;
  594.     }
  595.     
  596.     setParent $parent;
  597.     
  598.     // Scene segmenting
  599.         
  600.     if (!$justFill) {
  601.         columnLayout -adj true $np_wsRuleList;
  602.         frameLayout -borderVisible true -borderStyle "etchedIn"
  603.             -collapsable true -collapse false 
  604.             -l "Scene File Locations" ("Defaults_F");
  605.         columnLayout ("Objects_Defaults_L");
  606.     }
  607.     
  608.     // Scene directories
  609.  
  610.     $listSize = size($objectWidgets);
  611.     for ($index = 0; $index < $listSize; $index += 4)
  612.     {
  613.         string $label = $objectWidgets[$index];
  614.         string $name  = "np_ObjectLocation" + $objectWidgets[$index + 1];
  615.         string $value = $objectWidgets[$index + 3];
  616.  
  617.         if (!$justFill)
  618.         {
  619.             textFieldGrp
  620.                 -editable $bEditable
  621.                 -label $label
  622.                 -fileName $value
  623.                 $name;
  624.         }
  625.         else
  626.         {
  627.             textFieldGrp -e
  628.                 -fileName $value
  629.                 $name;
  630.         }
  631.     }
  632.     
  633.     setParent $np_wsRuleList;
  634.     
  635.     // Rendering directories
  636.     
  637.     if (!$justFill) {
  638.         frameLayout -borderVisible true -borderStyle "etchedIn"
  639.             -collapsable true -collapse false 
  640.             -l "Project Data Locations"
  641.             ("RenderLocations_Defaults_F");
  642.         columnLayout ("RenderLocations_Defaults_L");
  643.     }
  644.  
  645.     $listSize = size($renderWidgets);
  646.     for ($index = 0; $index < $listSize; $index += 4)
  647.     {
  648.         string $label = $renderWidgets[$index];
  649.         string $name  = "np_RenderLocation" + $renderWidgets[$index + 1];
  650.         string $value = $renderWidgets[$index + 3];
  651.  
  652.         if ($justFill) {
  653.             textFieldGrp -e -fileName $value $name;
  654.         } else {
  655.             textFieldGrp -editable $bEditable -fileName $value -l $label $name;
  656.         }
  657.     }
  658.             
  659.     setParent $np_wsRuleList;
  660.     
  661.     // Data transfer directories
  662.     
  663.     if (!$justFill) {
  664.         frameLayout -borderVisible true -borderStyle "etchedIn"
  665.             -collapsable true -collapse false 
  666.             -l "Data Transfer Locations" 
  667.             ("DataTransferLocations_Defaults_F");
  668.         columnLayout ("DataTransferLocations_Defaults_L");
  669.     }
  670.  
  671.     $listSize = size($fileRuleWidgets);
  672.     for ($index = 0; $index < $listSize; $index += 4)
  673.     {
  674.         string $label = $fileRuleWidgets[$index];
  675.         string $name  = "np_FileLocation" + $fileRuleWidgets[$index + 1];
  676.         string $value = $fileRuleWidgets[$index + 3];
  677.  
  678.         if ($justFill) {
  679.             textFieldGrp -e -fileName $value $name;
  680.         } else {
  681.             textFieldGrp -editable $bEditable -fileName $value -l $label $name;
  682.         }
  683.     }
  684.     setParent $np_wsRuleList;
  685. }
  686.  
  687. global proc int np_setNewLocation( string $path, string $type )
  688. {
  689.     string $wsLocationCtl = ("wsLocation0");
  690.  
  691.     // All we do on a successful browse is set the control in the
  692.     // 'New Project' window - if user accepts this choice all the
  693.     // workspace stuff will be set up at that point
  694.     if ( `textFieldButtonGrp -ex $wsLocationCtl` )
  695.     {
  696.         textFieldButtonGrp -e -fi $path $wsLocationCtl;
  697.         return true;
  698.     }
  699.  
  700.     // If we got here, then the user may have either accepted the
  701.     // new project settings from the New Project window, or cancelled
  702.     // the New Project window. In either case, the following should
  703.     // be valid:
  704.     string $wsDir = `workspace -q -fn`;
  705.     if ( `file -q -ex $wsDir` )
  706.         workspace -dir $wsDir;
  707.  
  708.     return false;
  709. }
  710.  
  711. global proc np_browseForNewLocation()
  712. {
  713.     string $wsDir;
  714.     string $wsLocationCtl = ("wsLocation0");
  715.  
  716.     if ( `textFieldButtonGrp -ex $wsLocationCtl` )
  717.     {
  718.         $wsDir = `textFieldButtonGrp -q -fi $wsLocationCtl`;
  719.         // Have to set the workspace dir so the fileBrowser knows
  720.         // where to start looking
  721.         if ( `file -q -ex $wsDir` )
  722.             workspace -dir $wsDir;
  723.     }
  724.  
  725.     fileBrowser "np_setNewLocation" "Select Location" "" 4;
  726. }
  727.  
  728. global proc np_setupNewInfo ( )
  729. {
  730.     string  $parent = "wsSetupInfo";
  731.  
  732.     string $wsLocationCtl = ("wsLocation0");
  733.     string $np_wsNameCtl = ("np_wsName0");
  734.     string $wsScrollCtl = ("wsScroll0");
  735.     int $enabled = 1;
  736.     
  737.     button -e -enable $enabled acceptSetup;
  738.     
  739.     if (!`textFieldButtonGrp -ex $np_wsNameCtl`) {
  740.         string $currentDir = "";
  741.         // Check for environment variable first
  742.         $currentDir = getenv("MAYA_PROJECTS_DIR");
  743.         if(size($currentDir) == 0) {
  744.             // Environment var is not set, so check for option var now
  745.             if(`optionVar -ex "ProjectsDir"`) {
  746.                 $currentDir = `optionVar -q "ProjectsDir"`;
  747.             }
  748.             if(size($currentDir) == 0) {
  749.                 // Option var is not set too. Get the root directory of the current workspace
  750.                 $currentDir = dirname( `workspace -q -fn` );
  751.             }
  752.         }
  753.         setParent $parent;
  754.             textFieldButtonGrp -editable $enabled 
  755.                 -l "Name" 
  756.                 -text "New_Project" 
  757.                 -buttonLabel "Help...   "
  758.                 -buttonCommand "showHelp NewProject"
  759.                 $np_wsNameCtl;
  760.             textFieldButtonGrp -editable $enabled 
  761.                 -l "Location" 
  762.                 -fileName $currentDir 
  763.                 -bl "Browse.."
  764.                 -bc np_browseForNewLocation $wsLocationCtl;
  765.             scrollLayout -cr true $wsScrollCtl;
  766.                 np_showSetup ( "", $wsScrollCtl, 0, $enabled);
  767.  
  768.         
  769.         formLayout -e 
  770.             -af $wsLocationCtl left 0 
  771.             -af $wsLocationCtl right 0 
  772.             -ac $wsLocationCtl top 0 $np_wsNameCtl
  773.             -af $np_wsNameCtl left 0 
  774.             -af $np_wsNameCtl right 0 
  775.             -af $np_wsNameCtl top 5  
  776.             -af $wsScrollCtl left 0 
  777.             -af $wsScrollCtl right 0 
  778.             -af $wsScrollCtl bottom 0 
  779.             -ac $wsScrollCtl top 3 $wsLocationCtl  
  780.                 $parent;
  781.     }
  782. }
  783.  
  784. global proc np_setupEditInfo ( )
  785. {
  786.     string  $parent = "wsSetupInfo";
  787.  
  788.     string $wsLocationCtl = ("wsLocation0");
  789.     string $np_wsNameCtl = ("np_wsName0");
  790.     string $wsScrollCtl = ("wsScroll0");
  791.     
  792.     button -e -enable 1 acceptSetup;
  793.     
  794.     if (!`textFieldGrp -ex $np_wsNameCtl`) {
  795.         string $workspace = `workspace -q -fn`;        // Get the current WS name.
  796.         string $wsLocation = dirname( $workspace );
  797.         string $wsName = basename( $workspace, "" );
  798.  
  799.         setParent $parent;
  800.             textFieldButtonGrp -l "Name" 
  801.                 -editable false
  802.                 -text $wsName
  803.                 -buttonLabel "Help...   "
  804.                 -buttonCommand "showHelp EditProject"
  805.                 $np_wsNameCtl;
  806.             textFieldGrp -l "Location"
  807.                 -editable false 
  808.                 -fileName $wsLocation 
  809.                 $wsLocationCtl;
  810.  
  811.             scrollLayout -cr true $wsScrollCtl;
  812.                 np_showSetup ( $workspace, $wsScrollCtl, 0, 1);
  813.         
  814.         formLayout -e 
  815.             -af $wsLocationCtl left 0 
  816.             -af $wsLocationCtl right 0 
  817.             -ac $wsLocationCtl top 0 $np_wsNameCtl
  818.             -af $np_wsNameCtl left 0 
  819.             -af $np_wsNameCtl right 0 
  820.             -af $np_wsNameCtl top 5 
  821.             -af $wsScrollCtl left 0 
  822.             -af $wsScrollCtl right 0 
  823.             -af $wsScrollCtl bottom 0 
  824.             -ac $wsScrollCtl top 3 $wsLocationCtl
  825.             $parent;
  826.     }
  827. }
  828.  
  829.  
  830. global proc string np_displayWSSetup ( string $parent, int $mode )
  831. //
  832. //    Parameters:
  833. //        $parent        - the parent control layout.
  834. //        $mode        - 1 == new project
  835. //                      2 == edit project.
  836. //
  837. {
  838.     setParent $parent;        
  839.  
  840.     string $callback;
  841.  
  842.     if ($mode == 1) {
  843.         $callback = "if (np_createNewProjectCallback()) deleteUI newProjectWindow;";
  844.     } else if ($mode == 2) {
  845.         $callback = "np_editProjectCallback;deleteUI newProjectWindow";
  846.     }
  847.  
  848.     int $numDivisions = 100;
  849.     formLayout -nd $numDivisions WSsetupForm;
  850.         formLayout setupControlArea;
  851.             button -l "Accept" -width 110 -c $callback acceptSetup;
  852.             if ($mode == 1) {
  853.                 button -l "Use Defaults" -width 110 -c "np_resetDefaults" defaultSetup;
  854.             }
  855.             button -l "Cancel" -width 110 -c "deleteUI newProjectWindow;" cancelSetup;
  856.             
  857.             formLayout -e 
  858.                 -af acceptSetup "left" 5
  859.                 -af acceptSetup "bottom" 5
  860.                 -an acceptSetup "top"
  861.                 -af cancelSetup "bottom" 5
  862.                 -af cancelSetup "right" 5
  863.                 -an cancelSetup "top"
  864.                 setupControlArea;
  865.  
  866.             // Only have the "Use Defaults" button in "new" mode since the
  867.             // user shouldn't be making radical changes to a created project.
  868.             //
  869.             if ($mode == 1) {
  870.                 formLayout -e 
  871.                     -ap acceptSetup "right" 0 33
  872.                     -af defaultSetup top 0 
  873.                     -ac defaultSetup left 5 acceptSetup
  874.                     -ap defaultSetup right 0 66
  875.                     -af defaultSetup bottom 5
  876.                     -ac cancelSetup "left" 5 defaultSetup
  877.                     setupControlArea;
  878.             } else {
  879.                 formLayout -e 
  880.                     -ap acceptSetup "right" 3 50
  881.                     -ac cancelSetup "left" 5 acceptSetup
  882.                     setupControlArea;
  883.             }
  884.  
  885.                             
  886.         setParent WSsetupForm;
  887.         
  888.         formLayout wsSetupInfo;
  889.     
  890.         formLayout -e -af wsSetupInfo top 0 -af wsSetupInfo left 0
  891.                         -af wsSetupInfo right 0
  892.                         -ac wsSetupInfo bottom 5 setupControlArea
  893.                         -af setupControlArea left 0 -af setupControlArea right 0
  894.                         -af setupControlArea bottom 0
  895.                         -an setupControlArea top
  896.                         WSsetupForm;
  897.     
  898.     if ($mode == 1) {
  899.         np_setupNewInfo;    // Draw the first tab.
  900.     } if ($mode == 2) {
  901.         np_setupEditInfo;
  902.     }
  903.     
  904.     return "WSsetupForm";
  905. }
  906.  
  907. global proc projectSetup ( int $mode )
  908. //
  909. //    Description:
  910. //        Edit a new project if $mode = 2.
  911. //        Display a new project setup window if $mode = 1.
  912. //        Display the defaults if $mode = 0.  - defunct
  913. //
  914. {
  915. global string $gProjectSetupWorkspace;
  916.  
  917.     if (!`window -ex newProjectWindow`) {
  918.         window -iconName "Project" -wh 450 510 newProjectWindow;
  919.             tabLayout -tv false windowLayout;
  920.                 columnLayout dummyTab;
  921.     } else {
  922.         // remove the children 
  923.         string $childList[] = `tabLayout -q -ca windowLayout`;
  924.         int $numChildren = size($childList);
  925.         int $child;
  926.  
  927.         for ($child = 0; $child < $numChildren; $child++) {
  928.             deleteUI $childList[$child];
  929.         }
  930.  
  931.         setParent windowLayout;
  932.         columnLayout dummyTab;    // Make the dummy display tab.
  933.     }
  934.  
  935.     if ($mode == 2) {
  936.         // remember the current workspace (we need it for editing)
  937.         //
  938.         $gProjectSetupWorkspace = `workspace -query -fullName`;
  939.         window -e -t "Edit Project" newProjectWindow;
  940.         tabLayout -e -st dummyTab windowLayout;
  941.         string $newTab = `np_displayWSSetup windowLayout $mode`;
  942.         tabLayout -e -st $newTab windowLayout;
  943.     } else if ($mode == 1) {
  944.         // set the "current" workspace to nothing since there is none
  945.         //
  946.         $gProjectSetupWorkspace = "";
  947.         window -e -t "New Project" newProjectWindow;
  948.         tabLayout -e -st dummyTab windowLayout;
  949.         string $newTab = `np_displayWSSetup windowLayout $mode`;
  950.         tabLayout -e -st $newTab windowLayout;
  951.     }
  952.  
  953.     showWindow newProjectWindow;
  954. }
  955.